import React, {useEffect, useState} from "react";
import {Icon, Text} from "react-native-elements";
import {
    Button,
    Dimensions,
    ScrollView,
    StyleSheet,
    TextInput,
    TouchableHighlight,
    TouchableOpacity,
    View
} from "react-native";
import {fontSize_12, fontSize_14, fontSize_15, fontSize_16, fontSize_20} from "./theme";
import {
    addressBookSvgXml_Mine,
    arrowDownSvgXml,
    arrowRightSvgXml,
    closeeyeSvgXml,
    closeSvgXml, openeyeSvgXml,
    rightSvgXml
} from "../libs/svgXml";
import {SvgXml} from "react-native-svg";
import {
    checkAddress_ETH,
    getBalance,
    getGasLimit,
    getGasPrice, getTokenBalance,
    getTokenGasLimit, sendToken,
    sendTransfer_ETH
} from "./smartxL2Libs/smartxL2Web3";
import BigNumber from "bignumber.js";
import {
    getChainBaseByChainID,
    getTokenByChainID,
    getWalletInfo,
    getWalletUseFinger,
    nowWallet
} from "./smartxL2Libs/L2_Data";
import {ethers} from "ethers";
import {decodeInputDataHex, encodeInputDataHex, encodeInputDataString} from "./smartxL2Libs/L2_utils";
import {BottomSheet} from "react-native-elements/dist/bottomSheet/BottomSheet";
import SimpleToast from "react-native-simple-toast";
import WaitingModal from "../components/WaitingModal";
import FingerPrintPopup from "../components/FingerPrint/FingerPrint";
import {cs} from "./CommandCss/commandCss";

const {width,height,scale} = Dimensions.get("window");

const L2_transfer = ({navigation,route}:any) => {
    const [net,setNet] = useState()
    const [tokenAddress,setTokenAddress] = useState(route?.params?.tokenAddress)
    const [tokenName,setTokenName] = useState(route?.params?.tokenName)
    const [receiver,setReceiver] = useState(route?.params?.receiver || "")
    const [balance,setBalance] = useState("")
    const [amount,setAmount] = useState("")
    const [feeChecked,setFeeChecked] = useState("low")//low middle fast customize
    //发送交易的一些参数
    const [gasPriceGwei,setGasPriceGwei] = useState("")
    const [gasLimit,setGasLimit] = useState("21000")
    const [gasLimitAuto,setGasLimitAuto] = useState("21000")
    //输入data
    const [dataInput,setDataInput] = useState("")
    const [textInput,setTextInput] = useState("")
    const [showInput,setShowInput] = useState(false);
    const [inputTypeText,setInputTypeText] = useState(true)//true 纯文本 false 十六进制
    //显示交易详情
    const [showTransferDetail,setShowTransferDetail] = useState(false)
    //显示密码输入框
    const [showInputPassword,setShowInputPassword] = useState(false)
    const [passwordInput,setPasswordInput] = useState("")
    const [showPassword,setShowPassword] = useState(false)
    //转账中
    const [transfering,setTransfeting] = useState(false)
    //显示指纹解锁
    const [showFinger,setShowFinger] = useState(false)
    //是否使用指纹
    const [useFinger,setUseFinger] = useState(false)

    useEffect(() => {
        navigation.setOptions({
            title:"转账",
        })
        initWalletFinger()
        getGasPriceNow("");
        getBalanceNow();
        getNet();
    }, [])
    const initWalletFinger = async () => {
        let walletUseFinger = await getWalletUseFinger(nowWallet.chainID, nowWallet.address)
        console.log(`walletUseFinger:${walletUseFinger}`)
        setUseFinger(walletUseFinger)
    }
    const getGasPriceNow = async (data:string) => {
        try {
            let gasPrice_Ether = await getGasPrice();
            let gasPrice_Gwei = (new BigNumber(gasPrice_Ether)).multipliedBy("1000000000").dp(4, 1).toString();
            console.log(gasPrice_Gwei)
            setGasPriceGwei(gasPrice_Gwei)
            await getGasLimitNow(data)
        }
        catch (e) {
            console.log(e)
        }
    }
    const getBalanceNow = async () => {
        if(!tokenAddress)
        {
            let address = nowWallet.address;
            let balance = await getBalance(address);
            setBalance(balance)
            console.log(balance)
        }
        else
        {
            let tokenTemp = await getTokenByChainID(nowWallet.chainID,tokenAddress,nowWallet.address);
            if(tokenTemp)
            {
                setBalance(tokenTemp.balance)
            }
            let balance = await getTokenBalance(tokenAddress)
            if(balance.success)
            {
                setBalance(balance.data.balance)
            }
        }

    }
    const getNet = async () => {
        let net = await getChainBaseByChainID(nowWallet.chainID);
        console.log(net)
        if(net)
        {
            setNet(net)
        }

    }
    const getGasLimitNow = async (data:string) => {
        if(!tokenAddress)
        {
            let sendInfo = {
                // gasLimit:ethers.utils.parseUnits(gasLimit, "wei"),
                gasPrice: ethers.utils.parseUnits(gasPriceGwei, "gwei"),
                to: receiver,
                value: ethers.utils.parseEther(amount || "0"),
                data,
            }
            // console.log(sendInfo)
            let res = await getGasLimit(sendInfo)
            if(!res.success)
            {
                return ;
            }
            console.log(res.data.toNumber())
            let gasLimitTemp = res.data;
            if(gasLimitTemp)
            {
                console.log(ethers.utils.parseUnits(gasLimitTemp.toString(), "wei").toString())
                setGasLimit(ethers.utils.parseUnits(gasLimitTemp.toString(), "wei").toString())
                setGasLimitAuto(ethers.utils.parseUnits(gasLimitTemp.toString(), "wei").toString())
            }
            return ;
        }
        else
        {
           let gasLimitRes = await getTokenGasLimit(tokenAddress,receiver,amount);
           if(gasLimitRes.success)
           {
               let gaslimit = gasLimitRes.data.GasLimit;
               setGasLimit(ethers.utils.parseUnits(gaslimit.toString(), "wei").toString())
               setGasLimitAuto(ethers.utils.parseUnits(gaslimit.toString(), "wei").toString())
           }
        }

    }
    const checkInputInfo = async () => {
        if(!checkAddress_ETH(receiver))
        {
            SimpleToast.show("请输入正确的收款地址");
            return
        }
        let nowWalletDetail = await getWalletInfo(nowWallet.chainID,nowWallet.address)
        if(!nowWalletDetail || !nowWalletDetail.privateKey)
        {
            SimpleToast.show("请勿使用观察钱包转账");
            return
        }
        if(!tokenAddress)
        {
            let myBalance = balance;
            let amountTransAll = (new BigNumber(amount)).plus((new BigNumber(gasLimit || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")));
            console.log(amountTransAll,myBalance)
            if(amountTransAll.isGreaterThan(myBalance))
            {
                SimpleToast.show("余额不足");
                return
            }
        }
        else
        {

            let address = nowWallet.address;
            let balanceMain = await getBalance(address);
            let myBalance = new BigNumber(balanceMain);
            let gasFee = (new BigNumber(gasLimit)).multipliedBy(gasPriceGwei || "0").div("1000000000");
            if (myBalance.isLessThan(gasFee))
            {
                SimpleToast.show("手续费不足");
                return
            }
            let tokenBalance = new BigNumber(balance);
            if(tokenBalance.isLessThan(amount))
            {
                SimpleToast.show("余额不足");
                return
            }
        }

        console.log(dataInput)
        setShowTransferDetail(true)
    }
    const checkPasswordAndSendTransfer = async () => {
        let walletDetail = await getWalletInfo(nowWallet.chainID,nowWallet.address)
        if(!walletDetail || !walletDetail.privateKey)
        {
            SimpleToast.show("请勿使用观察钱包转账");
            return
        }
        if(walletDetail.password !== passwordInput)
        {
            SimpleToast.show("密码错误");
            return
        }
        setPasswordInput("")
        setShowPassword(false)
        setShowInputPassword(false)
        setTransfeting(true)
        if(!tokenAddress)
        {
            let res = await sendTransfer_ETH(receiver,amount,gasPriceGwei,gasLimit,dataInput);
            if(!res.success)
            {
                console.log(res.falseReason)
                SimpleToast.show(res.falseReason);
                setTransfeting(false)
                return ;
            }
        }
        else
        {
            let res = await sendToken(tokenAddress,receiver,amount,gasLimit,gasPriceGwei)
            if(!res.success)
            {
                console.log(res.falseReason)
                SimpleToast.show(res.falseReason);
                setTransfeting(false)
                return ;
            }
        }
        setTransfeting(false)
        navigation.navigate("L2_Tabs",{refresh:true});
    }
    const sendTransferByFinger = async (checkFingerRes: boolean) => {
        if (!checkFingerRes) {
            setShowInputPassword(true)
            return;
        }
        let walletDetail = await getWalletInfo(nowWallet.chainID,nowWallet.address)
        if(!walletDetail || !walletDetail.privateKey)
        {
            SimpleToast.show("请勿使用观察钱包转账");
            return
        }
        setPasswordInput("")
        setShowPassword(false)
        setShowInputPassword(false)
        setTransfeting(true)
        if(!tokenAddress)
        {
            let res = await sendTransfer_ETH(receiver,amount,gasPriceGwei,gasLimit,dataInput);
            if(!res.success)
            {
                console.log(res.falseReason)
                SimpleToast.show(res.falseReason);
                setTransfeting(false)
                return ;
            }
        }
        else
        {
            let res = await sendToken(tokenAddress,receiver,amount,gasLimit,gasPriceGwei)
            if(!res.success)
            {
                console.log(res.falseReason)
                SimpleToast.show(res.falseReason);
                setTransfeting(false)
                return ;
            }
        }
        setTransfeting(false)
        navigation.navigate("L2_Tabs",{refresh:true});
    }
    return (
        <View style={styles.container}>
            <ScrollView style={{width:width,backgroundColor:"#f6f6f6"}} contentContainerStyle={cs.f1} keyboardShouldPersistTaps={"always"}>
                <View style={styles.divider_10}/>
                <View style={{width:"100%",paddingTop:10,paddingLeft:10,paddingRight:10,backgroundColor:"white"}}>
                    <Text style={{fontSize:fontSize_14}}>收款地址</Text>
                    <TextInput
                        style={{
                            fontSize:fontSize_14,
                            width:width*0.7
                        }}
                        value={receiver}
                        multiline={true}
                        placeholder={"输入或者粘贴钱包地址"}
                        onChangeText={value => setReceiver(value.trim())}
                        onEndEditing={()=>{getGasPriceNow(dataInput)}}
                    />
                    <SvgXml onPress={()=>{
                        navigation.navigate('L2_AddressBookView')
                    }} xml={addressBookSvgXml_Mine} width={20} height={20}
                            style={{position:"absolute",right:10,top:10}}
                    />
                </View>
                <View style={styles.divider_10}/>
                <View style={{paddingTop:10,width:"100%",paddingLeft:10,paddingRight:10,backgroundColor:"white"}}>
                    <Text style={{fontSize:fontSize_14}}>转账金额</Text>
                    <TextInput
                        keyboardType={"numeric"}
                        style={{
                            fontSize:fontSize_14,
                            paddingBottom:5,
                            borderBottomWidth:1/scale
                        }}
                        value={amount}
                        placeholder={"请输入数量"}
                        onChangeText={value => {
                            // @ts-ignore
                            let replace = value.match(/^\d*(\.?\d{0,18})/g)[0];
                            setAmount(replace)
                        }}
                        onEndEditing={()=>{getGasPriceNow(dataInput)}}
                    />
                    <View style={{flexDirection:"row",alignItems:"center",justifyContent:"space-between",width:"100%",height:40}}>
                        <Text style={{fontSize:fontSize_14}}>钱包余额</Text>
                        <Text style={{color:"#a0a2a7"}}>{balance} {tokenAddress?tokenName:(net?net.coinName : "")}</Text>
                    </View>
                    <Text style={{position:"absolute",right:10,top:10,fontSize:fontSize_14}}>{tokenAddress?tokenName:(net?net.coinName : "")} ></Text>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        setAmount(balance)
                    }} style={{position:"absolute",right:10,top:44,
                        borderWidth:1/scale,borderRadius:14,paddingLeft:5,paddingRight:5,borderColor:"#bfc1c3"}}>
                        <Text style={{fontSize:fontSize_14,color:"#bfc1c3"}}>全部</Text>
                    </TouchableHighlight>
                </View>
                <View style={styles.divider_20}/>
                <Text style={{width:"100%",fontSize:fontSize_14,alignSelf:"flex-start",paddingTop:10,paddingLeft:10,paddingRight:10,paddingBottom:10,backgroundColor:"white"}}>矿工费</Text>
                <View style={{width:"100%",flexDirection:"row",justifyContent:"space-between",paddingLeft:10,paddingRight:10,backgroundColor:"white"}}>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        getGasPriceNow(dataInput)
                        setFeeChecked("low")
                    }}>
                        <View style={feeChecked==="low"?styles.checkFee:styles.unCheckFee}>
                            <Text style={feeChecked==="low"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>慢</Text>
                            <Text style={feeChecked==="low"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>{(new BigNumber(gasLimitAuto || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")).toFixed(6)+" "+(net?net.coinName : "")}</Text>
                            <Text style={feeChecked==="low"?styles.checkValueFee:styles.unCheckValueFee}>≈ $ 0.35</Text>
                            <Text style={feeChecked==="low"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>≤1分钟</Text>
                        </View>
                    </TouchableHighlight>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        getGasPriceNow(dataInput)
                        setFeeChecked("middle")
                    }}>
                        <View style={feeChecked==="middle"?styles.checkFee:styles.unCheckFee}>
                            <Text style={feeChecked==="middle"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>推荐</Text>
                            <Text style={feeChecked==="middle"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>{(new BigNumber(gasLimitAuto || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")).toFixed(6)+" "+(net?net.coinName : "")}</Text>
                            <Text style={feeChecked==="middle"?styles.checkValueFee:styles.unCheckValueFee}>≈ $ 0.35</Text>
                            <Text style={feeChecked==="middle"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>≤1分钟</Text>
                        </View>
                    </TouchableHighlight>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        getGasPriceNow(dataInput)
                        setFeeChecked("fast")
                    }}>
                        <View style={feeChecked==="fast"?styles.checkFee:styles.unCheckFee}>
                            <Text style={feeChecked==="fast"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>快</Text>
                            <Text style={feeChecked==="fast"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>{(new BigNumber(gasLimitAuto || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")).toFixed(6)+" "+(net?net.coinName : "")}</Text>
                            <Text style={feeChecked==="fast"?styles.checkValueFee:styles.unCheckValueFee}>≈ $ 0.35</Text>
                            <Text style={feeChecked==="fast"?styles.checkFeeFontSize:styles.uncheckFeeFontSize}>≤1分钟</Text>
                        </View>
                    </TouchableHighlight>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        getGasPriceNow(dataInput)
                        setFeeChecked("customize")
                    }}>
                        <View style={feeChecked==="customize"?styles.checkFee:styles.unCheckFee}>
                            <Text style={{fontSize:fontSize_14,color:feeChecked==="customize"?"#2980fe":"#6f7174"}}>自定义</Text>
                        </View>
                    </TouchableHighlight>
                </View>
                <View style={{width:"100%",padding:10,backgroundColor:"white"}}>
                    {
                        feeChecked==="customize"?
                            <View style={{width:"100%",padding:20,paddingLeft:10,paddingRight:10,backgroundColor:"#f5f6f7"}}>
                                <View style={{flexDirection:"row"}}>
                                    <Text style={{fontSize:fontSize_12,marginBottom:10}}>自定义矿工费</Text>
                                </View>
                                <View style={{flexDirection:"row"}}>
                                    <View style={{flexDirection:"column",flex:1}}>
                                        <Text style={{fontSize:10,lineHeight:20}}>
                                            Gas Price (Gwei)
                                        </Text>
                                        <TextInput
                                            style={{
                                                fontSize:fontSize_12,
                                                width:"100%",
                                                padding:7,
                                                backgroundColor:"white",
                                                borderRadius:5
                                            }}
                                            keyboardType={"numeric"}
                                            value={gasPriceGwei}
                                            placeholder={"请输入GasPrice"}
                                            onChangeText={value => {
                                                if(new BigNumber(value).isLessThan("0.00000001") && !(new BigNumber(value).isEqualTo(0)) )
                                                {
                                                    value = "0.00000001"
                                                }
                                                setGasPriceGwei(value.trim())
                                            }}
                                        />
                                        <Text style={{marginTop:10,fontSize:fontSize_12,width:"90%"}}>预计时间:1分钟</Text>
                                    </View>
                                    <View style={{flexDirection:"column",flex:1,marginLeft:20}}>
                                        <Text style={{fontSize:10,lineHeight:20}}>
                                            Gas Limit (gas)
                                        </Text>
                                        <TextInput
                                            keyboardType={"numeric"}
                                            style={{
                                                fontSize:fontSize_12,
                                                width:"100%",
                                                padding:7,
                                                backgroundColor:"white",
                                                borderRadius:5
                                            }}
                                            value={gasLimit}
                                            placeholder={"请输入GasLimit"}
                                            onChangeText={value => setGasLimit(value.trim())}
                                        />
                                        <Text style={{marginTop:10,fontSize:fontSize_12,width:"100%",textAlign:"right"}}>{(new BigNumber(gasLimit || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")).toFixed()+" "+(net?net.coinName : "")}</Text>
                                    </View>
                                </View>
                            </View>
                            :
                            null
                    }
                </View>
                {
                    tokenAddress?
                        null:
                        <View style={{width:"100%",padding:10,backgroundColor:"white"}}>
                            <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                                setShowInput(!showInput)
                            }} style={{flexDirection:"row",justifyContent:"flex-end"}}>
                                <View style={{flexDirection:"row",justifyContent:"flex-end",alignItems:"center"}}>
                                    <Text style={{fontSize:fontSize_12,color:"#2980fe"}}>高级功能</Text>
                                    {
                                        showInput?
                                            <SvgXml xml={arrowDownSvgXml("#2980fe")} width={17} height={17} />
                                            :
                                            <SvgXml xml={arrowRightSvgXml("#2980fe")} width={17} height={17} />
                                    }
                                </View>
                            </TouchableHighlight>
                        </View>
                }
                <View style={{width:"100%",padding:10,backgroundColor:"white"}}>
                    {
                        showInput?
                            <View>
                                <View style={{flexDirection:"row",justifyContent:"space-between"}}>
                                    <Text style={{fontSize:fontSize_14}}>上链数据</Text>
                                    <View style={{flexDirection:"row",width:121,height:20,backgroundColor:"white",borderRadius:5,borderWidth:1/scale,borderColor:"#2980fe"}}>
                                        <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                                            setInputTypeText(true)
                                        }} style={{flex:1,backgroundColor:!inputTypeText?"white":"#2980fe",borderRadius:5,borderTopRightRadius:0,borderBottomRightRadius:0,alignItems:"center",justifyContent:"center"}}>
                                            <Text style={{fontSize:12,color:inputTypeText?"white":"#2980fe"}}>纯文本</Text>
                                        </TouchableHighlight>
                                        <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                                            setInputTypeText(false)
                                        }} style={{marginLeft:1,flex:1,backgroundColor:inputTypeText?"white":"#2980fe",borderRadius:5,borderTopLeftRadius:0,borderBottomLeftRadius:0,alignItems:"center",justifyContent:"center"}}>
                                            <Text style={{fontSize:12,color:!inputTypeText?"white":"#2980fe"}}>十六进制</Text>
                                        </TouchableHighlight>
                                    </View>
                                </View>
                                <TextInput
                                    style={{
                                        fontSize:fontSize_14,
                                        width:"100%",
                                        backgroundColor:"#f5f6f7",
                                        padding:10,
                                        marginTop:10,
                                        minHeight:70,
                                        textAlign:"left",
                                        textAlignVertical:"top"
                                    }}
                                    multiline={true}
                                    placeholder={"该数据会写入区块链，并且小号一定的费用"}
                                    value={textInput}
                                    onChangeText={(value)=>{setTextInput(value)}}
                                    onEndEditing={()=>{
                                        if(inputTypeText)
                                        {
                                            let dataTemp = encodeInputDataString(textInput);
                                            setDataInput(dataTemp)
                                            console.log(dataTemp)
                                            getGasPriceNow(dataTemp)
                                            return;
                                        }
                                        let dataTemp2 = encodeInputDataHex(textInput);
                                        setDataInput(dataTemp2)
                                        getGasPriceNow(dataTemp2)
                                        return;
                                    }}
                                />
                            </View>
                            :null
                    }

                </View>
                <View style={{flex:1,minHeight:50,backgroundColor:"#f6f6f6",width:width,alignItems:"center",marginTop:20,paddingLeft:10,paddingRight:10}}>
                    <View style={{flex:1}}/>
                    <TouchableHighlight underlayColor={"transparent"} onPress={()=>{
                        // sendTransfer_ETH(receiver,amount,gasPriceGwei,gasLimit,dataInput);
                        checkInputInfo();
                    }}>
                        <View style={styles.sendBTN}>
                            <Text style={{fontSize:fontSize_15,color:"white"}}>确认</Text>
                        </View>
                    </TouchableHighlight>
                </View>
            </ScrollView>
            <BottomSheet
                modalProps={{animationType:"fade"}}
                isVisible={showTransferDetail}
            >
                <View
                    style={{width:width,height:height,backgroundColor: 'rgba(0.5, 0.25, 0, 0.2)'}}
                >
                    <TouchableHighlight
                        underlayColor={"transparent"}
                        onPress={()=>{
                            setShowTransferDetail(false)
                        }}
                        style={{flex:1,backgroundColor:"rgba(0.5, 0.25, 0, 0.2)"}}
                    >
                        <View style={{flex:1}}/>
                    </TouchableHighlight>
                    <View style={{width:width,height:45,backgroundColor:"#fcfdff",borderBottomWidth:1/scale,borderBottomColor:"#ecedef",justifyContent:"center",alignItems:"center"}}>
                        <Text style={{fontSize:fontSize_16}}>交易详情</Text>
                        <View style={{position:"absolute",width:"100%",height:"100%",left:0,top:0,alignItems:"flex-end",justifyContent:"center",paddingRight:10,paddingLeft:10}}>
                            <SvgXml xml={closeSvgXml()} width={20} height={20} onPress={()=>{
                                setShowTransferDetail(false)
                            }}/>
                        </View>
                    </View>
                    <Text style={{width:width,textAlign:"center",lineHeight:70,fontSize:fontSize_20,backgroundColor:"white"}}>{amount} {tokenAddress?tokenName:(net?net.coinName : "")}</Text>
                    <View style={{flexDirection:"row",backgroundColor:"white",paddingTop:15,paddingBottom:15,borderBottomWidth:1/scale,borderBottomColor:"#f0f0f0"}}>
                        <Text style={{fontSize:fontSize_14,color:"#aaaaaa",width:100,paddingLeft:10,backgroundColor:"white"}}>付款地址</Text>
                        <Text style={{flex:1,flexWrap:"wrap",paddingLeft:10,paddingRight:30,fontSize:fontSize_14}}>{nowWallet.address}</Text>
                    </View>
                    <View style={{flexDirection:"row",backgroundColor:"white",paddingTop:15,paddingBottom:15,borderBottomWidth:1/scale,borderBottomColor:"#f0f0f0"}}>
                        <Text style={{fontSize:fontSize_14,color:"#aaaaaa",width:100,paddingLeft:10,backgroundColor:"white"}}>收款地址</Text>
                        <Text style={{flex:1,flexWrap:"wrap",paddingLeft:10,paddingRight:30,fontSize:fontSize_14}}>{receiver}</Text>
                    </View>
                    <View style={{flexDirection:"row",backgroundColor:"white",paddingTop:15,paddingBottom:15,borderBottomWidth:1/scale,borderBottomColor:"#f0f0f0"}}>
                        <Text style={{fontSize:fontSize_14,color:"#aaaaaa",width:100,paddingLeft:10,backgroundColor:"white"}}>矿工费</Text>
                        <Text style={{flex:1,flexWrap:"wrap",paddingLeft:10,paddingRight:30,fontSize:fontSize_14}}>
                            {(new BigNumber(gasLimit || "0").multipliedBy(gasPriceGwei || "0").div("1000000000")).toFixed()+" "+(net?net.coinName : "")}
                            {"\n"}
                            <Text style={{fontSize:fontSize_12,color:"#aaaaaa",lineHeight:20}}>{`≈ Gas(${gasLimit}) * Gas Price(${gasPriceGwei} Gwei)`}</Text>
                        </Text>
                    </View>
                    {
                        textInput?
                          <View style={{flexDirection:"row",backgroundColor:"white",paddingTop:15,paddingBottom:15,borderBottomWidth:1/scale,borderBottomColor:"#f0f0f0"}}>
                              <Text style={{fontSize:fontSize_14,color:"#aaaaaa",width:100,paddingLeft:10,backgroundColor:"white"}}>备注</Text>
                              <Text style={{flex:1,flexWrap:"wrap",paddingLeft:10,paddingRight:30,fontSize:fontSize_14}}>
                                  {decodeInputDataHex(dataInput)}
                              </Text>
                          </View>:null
                    }

                    <View style={{padding:10,backgroundColor:"white",paddingTop:30,paddingBottom:20}}>
                        <Button title={"确认支付"} onPress={()=>{
                            setShowTransferDetail(false)
                            if(useFinger)
                            {
                                setShowFinger(true)
                                return
                            }
                            setShowInputPassword(true)
                        }}/>
                    </View>
                </View>
            </BottomSheet>
            <BottomSheet
                modalProps={{animationType:"fade"}}
                isVisible={showInputPassword}
            >
                <TouchableHighlight underlayColor={"rgba(0.5, 0.25, 0, 0.2)"}
                                    style={[cs.w_100,cs.h_h,cs.f1,cs.ac,cs.jc]}
                                    onPress={()=>{
                                        setPasswordInput("")
                                        setShowPassword(false)
                                        setShowInputPassword(false)
                                    }}>
                    <ScrollView contentContainerStyle={[cs.f1,cs.w_100,cs.ac,cs.jc]} keyboardShouldPersistTaps={"always"} style={[cs.f1,cs.w_100]}>
                        <View style={{borderRadius:5,width:"100%",alignItems:"center"}}>
                            <View style={{
                                width:"80%",
                                backgroundColor:"#f5f6f8",
                                padding:20,
                                borderTopRightRadius:5,
                                borderTopLeftRadius:5,
                                alignItems:"center",
                                borderBottomWidth:1/scale,
                                borderBottomColor:"#b4b5b7",
                            }}>
                                <Text style={{fontSize:fontSize_16,fontWeight:"bold",marginBottom:20}}>输入密码</Text>
                                <View style={{
                                    width:"100%",
                                    backgroundColor:"white",
                                    padding:5,
                                    borderRadius:5,
                                    borderWidth:1/scale,
                                    borderColor:"#bebfc1"}}>
                                    <TextInput
                                        secureTextEntry={!showPassword}
                                        placeholder={"请输入钱包密码"}
                                        style={{
                                            width:"80%",
                                            fontSize:fontSize_16,
                                            padding:0
                                        }}
                                        onChangeText={(value)=>{setPasswordInput(value.trim())}}
                                    />
                                    <SvgXml xml={showPassword?openeyeSvgXml("#9c9c9c"):closeeyeSvgXml("#9c9c9c")} width={20} height={20} onPress={()=>{
                                        setShowPassword(!showPassword)
                                    }}
                                            style={{
                                                position:"absolute",
                                                right:15,
                                                bottom:8
                                            }}
                                    />
                                </View>
                            </View>
                            <View style={{
                            width:"80%",
                            height:45,
                            backgroundColor:"#f5f6f8",
                            borderBottomRightRadius:5,
                            borderBottomLeftRadius:5,
                            flexDirection:"row"
                        }}>
                            <TouchableHighlight underlayColor={"#f5f6f8"} style={{flex:1,alignItems:"center",justifyContent:"center",borderRightWidth:1/scale,borderRightColor:"#b4b5b7"}}
                                                onPress={()=>{
                                                    setPasswordInput("")
                                                    setShowPassword(false)
                                                    setShowInputPassword(false)
                            }}>
                                <Text style={{fontSize:fontSize_14}}>
                                    取消
                                </Text>
                            </TouchableHighlight>
                            <TouchableHighlight underlayColor={"#f5f6f8"} style={{flex:1,alignItems:"center",justifyContent:"center"}} onPress={()=>{
                                checkPasswordAndSendTransfer()
                            }}>
                                <Text style={{fontSize:fontSize_14}}>
                                    确认
                                </Text>
                            </TouchableHighlight>
                        </View>
                        </View>
                    </ScrollView>
                </TouchableHighlight>
            </BottomSheet>
            {
                showFinger?
                    <FingerPrintPopup setShowFingerPrint={setShowFinger} dispatch={sendTransferByFinger}/>
                    :
                    null
            }
            <WaitingModal show={transfering} prompt={""}/>
        </View>
    )
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        width: width,
        alignItems: "center",
        justifyContent:"center",
        flexDirection: "column",
        paddingLeft:10,
        paddingRight:10,
        backgroundColor: "white"
    },
    divider_10:{
        width:width,
        height:10,
        backgroundColor:"#f6f6f6",
        marginLeft:-10
    },
    divider_20:{
        width:width,
        height:20,
        backgroundColor:"#f6f6f6",
        marginLeft:-10
    },
    checkFee:{
        width:(width-20-20)/4,
        height:90,
        padding:5,
        backgroundColor:"#8cbbfe55",
        alignItems:"center",
        justifyContent:"center",
        borderWidth:1/scale,
        borderColor:"#2980fe",
        borderRadius:5
    },
    unCheckFee:{
        width:(width-20-20)/4,
        height:90,
        padding:5,
        backgroundColor:"#ffffff",
        alignItems:"center",
        justifyContent:"center",
        justifyContent:"center",
        borderWidth:1/scale,
        borderRadius:5
    },
    unCheckValueFee:{
        width:"100%",
        textAlign:"center",
        paddingBottom:5,
        lineHeight:20,
        fontSize:10,
        borderBottomWidth:1/scale,
        borderBottomColor:"#f1f2f3",
    },
    checkValueFee:{
        width:"100%",
        textAlign:"center",
        paddingBottom:5,
        lineHeight:20,
        fontSize:10,
        borderBottomWidth:1/scale,
        borderBottomColor:"#2980fe",
        color:"#2980fe"
    },
    checkFeeFontSize:{
        fontSize:10,
        color:"#2980fe",
        lineHeight:17,
    },
    uncheckFeeFontSize:{
        fontSize:10,
        color:"#6f7174",
        lineHeight:17,
    },
    sendBTN:{
        marginTop:20,
        marginBottom:40,
        width:width-20,
        borderRadius:5,
        height:40,
        backgroundColor:"#2980fe",
        alignItems:"center",
        justifyContent:"center",
    }


})
export default L2_transfer;


